<?php

App::uses('AppController', 'Controller');

class PagesController extends AppController {

	var $name = 'Pages';
	var $uses = array('Category');


	/**
	 *
	 * @param type  meta
	 * @return type  meta
	 * @access public
	 */
	function index( $type = 'home') {
		
		$category = $this->Category->getInfoByType($type); 
		$this->set('category', $category); 

		// Set Website title
        $this->set('title_for_layout' , $category['Category']['web_title']);
	}
	
	/**
	 * Detail category
	 *
	 * @param type  meta
	 * @return type  meta
	 * @access public
	 */
	function detail($id = null) {
		if(empty($id)) $this->redirect('/');
		
		$category = $this->Category->read(null, (int)$id);
		$this->set('info', $category);
		
		// Get danh muc con
		if($category['Category']['parent_id'] == 0 ) {
			$parent_id = $id;
			$this->set('category', $category);
		} else {
			$parent_id = $category['Category']['parent_id'];
			$this->set('category', $this->Category->read(null, (int)$parent_id));
		}
		
		$parent_cates = $this->Category->getAll($parent_id);
		$this->set('parent_cates', $parent_cates);
		
		// Set Website title
		$this->set('title_for_layout' , $category['Category']['web_title']);
	}

}
